<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<!-- <meta http-equiv="refresh" content="10"> -->
<title>美丽敲敲门大地图</title>
<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}

#container {
	height: 100%
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=DDbl4GuGNmDrLbKeaDsCzAeDfOGhdyET">
	//v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
	//v1.4版本及以前版本的引用方式：src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
</script>
</head>
<script language="javascript">
	var XMLHttpReq;
	//创建XMLHttpRequest对象         
	function createXMLHttpRequest() {
		if (window.XMLHttpRequest) { //Mozilla 浏览器  
			XMLHttpReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE浏览器  
			try {
				XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
	}
</script>
<body>
	<div id="container"></div>
	<script type="text/javascript">
		var map = new BMap.Map("container"); // 创建地图实例  
		map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
		var point = new BMap.Point(115.851808, 28.694773); // 创建点坐标  
		var point2 = new BMap.Point(115.86999, 28.687675);
		map.centerAndZoom(point, 15); // 初始化地图，设置中心点坐标和地图级别

		var mapPoints;
		//查询按钮
		function search() {
			sendRequest();
		}

		//发送请求函数  
		function sendRequest() {
			createXMLHttpRequest();
			var url = window.location.protocol + "/mlqm/map/getlocation";
			//var url = "http://139.196.112.42/mlqm/map/getlocation";
			XMLHttpReq.open("GET", url, true);
			XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
			XMLHttpReq.send(null); // 发送请求  
		}

		// 处理返回信息函数  
		function processResponse() {
			if (XMLHttpReq.readyState == 4) { // 判断对象状态  
				if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息
					DisplayHot();
					//setTimeout("sendRequest()", 1000);
				} else { //页面不正常  
					window.alert("您所请求的页面有异常。");
				}
			}
		}//

		function DisplayHot() {
			var r = XMLHttpReq.responseText;
			if (r == "") {
				alert("未查找到！！！");
			} else {
				//var obj = eval(r);
				var obj = JSON.parse(r);
				var data = obj.data;
				//alert(data);
				mapPoints = data;
				var baseurl = window.location.protocol;
				for (var i = 0; i < mapPoints.length; i++) {
					if (mapPoints[i].type == "2") {
						//技师
						baseurl = window.location.protocol
								+ "/mMaps/images/webjishi.png";
						var tmp_point = new BMap.Point(mapPoints[i].longitude,
								mapPoints[i].latitude); // 创建点坐标
						var myIcon = new BMap.Icon(baseurl, new BMap.Size(40,
								150));
						var tmp_marker = new BMap.Marker(tmp_point, {
							icon : myIcon
						}); // 创建标注        
						var label = new BMap.Label("技师" + mapPoints[i].id, {
							offset : new BMap.Size(-15, -20)
						});
						tmp_marker.setLabel(label);
						map.addOverlay(tmp_marker); // 将标注添加到地图中
					} else {
						//客户
						/* baseurl = window.location.protocol
								+ "/mMaps/images/webkehu.png";
						var tmp_point = new BMap.Point(mapPoints[i].longitude,
								mapPoints[i].latitude); // 创建点坐标
						var myIcon = new BMap.Icon(baseurl, new BMap.Size(40,
								150));
						var tmp_marker = new BMap.Marker(tmp_point, {
							icon : myIcon
						}); // 创建标注 
						var label = new BMap.Label("客户" + mapPoints[i].id, {
							offset : new BMap.Size(-15, -20)
						});
						tmp_marker.setLabel(label);
						map.addOverlay(tmp_marker); // 将标注添加到地图中 */
					}
				}
			}
		}
		
		search();
		
		setInterval(function(){
			 doLocation();
       	},10000);
		
		function doLocation(){
			map.clearOverlays();
			search();
		}
	</script>
</body>
</html>